//
//  ClubTableViewCell.m
//  心水宝典
//
//  Created by zr on 2018/8/29.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "ClubTableViewCell.h"

@interface ClubTableViewCell ()

@property (nonatomic, weak)UIImageView * iconImageView;
@property (nonatomic, weak)UIImageView * contentImageView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UILabel * timeLabel;
@property (nonatomic, strong)UIButton * commitButton;
@property (nonatomic, strong)UIButton * likeButton;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation ClubTableViewCell


- (void)setModel:(AskListModel *)model{
    
    _model = model;
    
    NSURL * iconUrl = [NSURL URLWithString:model.head_link];
    
    [self.iconImageView sd_setImageWithURL:iconUrl placeholderImage:ImageNamed(@"23sdasas")];
    
    
    self.nameLabel.text = model.nickname;
    self.timeLabel.text = model.create_time;
    self.titleLabel.text = model.depict;
    
    NSArray * array = model.imglist_link;
    NSURL * url = [NSURL URLWithString:array.firstObject];
    [self.contentImageView sd_setImageWithURL:url];
    
    NSString * commit = [NSString stringWithFormat:@"  %@",model.comment];
    NSString * like = [NSString stringWithFormat:@"  %@",model.agrees];
    
    [self.commitButton setTitle:commit forState:UIControlStateNormal];
    [self.likeButton setTitle:like forState:UIControlStateNormal];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView * iconImageView = [UIImageView new];
    
    iconImageView.image = ImageNamed(@"23sdasas");
    iconImageView.layer.cornerRadius = 22 * SCREENH6;
    iconImageView.layer.masksToBounds = YES;
    
    self.iconImageView = iconImageView;
    
    [self.contentView addSubview:self.iconImageView];
    
    UIImageView * contentImageView = [UIImageView new];
    
    contentImageView.backgroundColor = [UIColor lightGrayColor];
    
    self.contentImageView = contentImageView;
    
    [self.contentView addSubview:self.contentImageView];
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.textColor = BLACK_COLOR;
    nameLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    nameLabel.text = @"神奇测试";
  
    self.nameLabel = nameLabel;
    
    [self.contentView addSubview:self.nameLabel];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = [UIColor lightGrayColor];
    titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    titleLabel.text = @"神奇测试：未来三个月，谁是你 的幸运天使。";
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    
    self.commitButton = [self setupButtonWithTitle:@"  2034" WithType:@"commit"];
    [self.contentView addSubview:self.commitButton];
    self.likeButton = [self setupButtonWithTitle:@"  2034" WithType:@"like"];
    [self.contentView addSubview:self.likeButton];
    
    
    UILabel * timeLabel = [UILabel new];
    
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    timeLabel.text = @"8-22";
    
    self.timeLabel = timeLabel;
    
    [self.contentView addSubview:self.timeLabel];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}

- (void)layoutSubviews{
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(10 * SCREENH6);
        make.width.height.mas_equalTo(44 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImageView);
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(5 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImageView.mas_bottom);
        make.leading.mas_equalTo(self.nameLabel);
    }];
    
    [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(25 * SCREENH6);
        make.width.height.mas_equalTo(140 * SCREENH6);
    }];
    
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentImageView);
        make.top.mas_equalTo(self.contentImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.commitButton.mas_trailing).offset(20 * SCREENH6);
        make.centerY.mas_equalTo(self.commitButton);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.likeButton);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}



- (UIButton *)setupButtonWithTitle:(NSString *)title WithType:(NSString *)type{
    
    UIButton * button = [UIButton new];
    
    NSString * image;
    if ([type isEqualToString:@"commit"]) {
        
        image = @"pinglun2";
    }else{
       
        image = @"zan";
    }
    [button setTitle:title forState:UIControlStateNormal];
    [button setImage:ImageNamed(image) forState:UIControlStateNormal];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    return button;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
